<?php
/**
 * User: @lose
 * Date: 2019-10-10
 * Time: 18:00
 */

namespace Biz\model\store;

use Doraemon\pockets\datebase\BaseDbModel;

class StoreCheck extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'store_check';

    const CHECK_DEFAULT = 0;//未审核
    const CHECK_SUCC = 1;//审核成功
    const CHECK_FAIL = 2;//审核失败

    const CHECK_MAP = [
        self::CHECK_DEFAULT => '未审核',
        self::CHECK_SUCC =>"审核成功",
        self::CHECK_FAIL => '审核失败'
    ];

    const STATUS_NORAML =1;
    const STATUS_DELET = 2;

    public static function getListByWhere($where, $field = '*')
    {
        $where['alias_status'] = self::STATUS_NORAML;
        return self::select($field, $where);
    }

    public static function getListByAdmin($where, $limit)
    {
        $condition  = [];
        $condition['LIMIT'] = $limit;
        $where['alias_status'] = self::STATUS_NORAML;
        if($where){
            $condition['AND'] = $where;
        }
        $condition['ORDER'] = ['addtime' => "DESC"];


        return self::select('*', $condition);
    }

    public static function add($data)
    {
        $result = self::insert($data)->rowCount();
        if($result) {
            return self::id();
        }

        return false;
    }

    public static function updateById($id, $data)
    {
        $result = self::update($data, ['id' => $id])->rowCount();
        if($result) {
            return $id;
        }

        return false;
    }

    public static function getInfo($id)
    {
        return self::get('*', ['id' => $id , 'alias_status' => self::STATUS_NORAML]);
    }

    public static function getCount($where)
    {
        $where['alias_status'] = self::STATUS_NORAML;
        return self::count($where);
    }

    public static function getAliasByStoreId($store_id = 0)
    {
        return self::select('*', ['store_id' => $store_id , 'alias_status' => self::STATUS_NORAML ]);
    }



}